# -*- coding: utf-8 -*-

from django import forms

from models import BlogList


class AddBlogForm(forms.ModelForm):
    class Meta:
        model = BlogList
        fields = ('url',)
        widgets = {
            'url': forms.TextInput(attrs={'class': 'form-control'}),
        }

    def __init__(self, *args, **kwargs):
        super(AddBlogForm, self).__init__(*args, **kwargs)
        self.fields['url'].label = u'博客地址'
        self.fields['url'].error_messages = {'required': u'请输入博客地址url'}
        self.fields['url'].widget.attrs['style'] = 'width: 500px;'


class EditBlogForm(forms.ModelForm):
    class Meta:
        model = BlogList
        fields = ('author', 'url')
        widgets = {
            'author': forms.Select(attrs={'disabled': 'disabled'}),
            'url': forms.TextInput(attrs={'class': 'form-control'}),
        }

    def __init__(self, *args, **kwargs):
        super(EditBlogForm, self).__init__(*args, **kwargs)
        self.fields['author'].label = u'姓 名'
        self.fields['url'].error_messages = {'required': u'URL地址'}
        self.fields['url'].widget.attrs['style'] = 'width: 500px;'


class BlogGradeForm(forms.ModelForm):
    class Meta:
        model = BlogList
        fields = ('author', 'url', 'grade', 'comment')
        widgets = {
            'author': forms.Select(attrs={'disabled': 'disabled'}),
            'url': forms.TextInput(attrs={'disabled': 'disabled'}),
            'grade': forms.Select(attrs={'class': 'form-control'}),
            'comment': forms.TextInput(attrs={'class': 'form-control'}),
        }

    def __init__(self, *args, **kwargs):
        super(BlogGradeForm, self).__init__(*args, **kwargs)
        self.fields['author'].label = u'姓 名'
        self.fields['url'].label = u'博客URL'
        self.fields['url'].widget.attrs['style'] = 'width: 500px;'
        self.fields['grade'].label = u'评 分'
        self.fields['grade'].error_messages = {'required': u'评分'}
        self.fields['comment'].label = u'评论'
        self.fields['comment'].required = False


class BlogListForm(forms.ModelForm):
    class Meta:
        model = BlogList
        widgets = {
            'author': forms.TextInput(attrs={'class': 'form-control'}),
            'url': forms.TextInput(attrs={'class': 'form-control'}),
            'grade': forms.Select(attrs={'class': 'form-control', 'size': '10'}),
            'comment': forms.TextInput(attrs={'class': 'form-control'}),
        }

    def __init__(self, *args, **kwargs):
        super(BlogListForm, self).__init__(*args, **kwargs)
        self.fields['author'].label = u'姓 名'
        self.fields['author'].error_messages = {'required': u'请输入姓名'}
        self.fields['url'].label = u'博客URL'
        self.fields['url'].error_messages = {'required': u'URL地址'}
        self.fields['grade'].label = u'评 分'
        self.fields['grade'].required = False
        self.fields['comment'].label = u'评 语'
        self.fields['comment'].required = False
